    var base64Codec = function (alphabet, padCharacter) {
      // Returns an object with 'encode' and 'decode' functions for the specified
      // 64-character 'alphabet'
      if (alphabet.length != 64) { throw new Error('Alphabet must be 64 characters.') };
      var codec = {};
      var decode_map = {};
      for (var i=0, n=alphabet.length; i < n; i++) {
        decode_map[alphabet[i]] = i;
      };
      // used to sniff out characters outside the alphabet
      var alphabet_inverse_regexp = new RegExp('[^' + alphabet.replace(/[\.\^\$\*\+\?\{\[\]\\\|\(\)]/g, '\\$&') + ']');
      codec.Base64CodecError = function (message) { this.message = message; };
      codec.Base64CodecError.prototype.toString = function () {
        return 'Base64CodecError' + (this.message ? ': ' + this.message : '');
      };
      var assertOrBadInput = function (expression, message) {
        if (!expression) { throw new codec.Base64CodecError(message) };
      };
      
      codec.encode = function (bytes, padOutput) {
        if (padOutput == null) { padOutput = true; }; // default to strict output
        assertOrBadInput(!(/[^\x00-\xFF]/.test(bytes)), 'Input contains out-of-range characters.'); // disallow two-byte chars
        var padding = '\x00\x00\x00'.slice((bytes.length % 3) || 3);
        bytes += padding; // pad with null bytes
        var out_array = [];
        for (var i=0, n=bytes.length; i < n; i+=3) {
          var newchars = (
            ((bytes.charCodeAt(i)  ) << 020) +
            ((bytes.charCodeAt(i+1)) << 010) +
            ((bytes.charCodeAt(i+2))));
          out_array.push(
            alphabet[(newchars >> 18) & 077],
            alphabet[(newchars >> 12) & 077],
            alphabet[(newchars >> 6)  & 077],
            alphabet[(newchars)       & 077]);      
        };
        output_padding = (padOutput && padCharacter !== undefined) ?
          Array(5).join(padCharacter).slice(-padding.length) :
          '';
        shorten(out_array, padding.length);
        return out_array.join('') + output_padding;
      };
      
      codec.decode = function (b64text, requirePadding, disallowWhitespace) {
        // by default don't require padding, and allow whitespace.
        if (!disallowWhitespace) { b64text = b64text.replace(/\s/g, ''); }; // kill whitespace
        if (padCharacter != null) {
          assertOrBadInput(!requirePadding || !(b64text.length % 4), 'Input length not divisible by 4.');
          b64text = rstrip(b64text, padCharacter)
        };
        assertOrBadInput(!alphabet_inverse_regexp.test(b64text), 'Input contains out-of-range characters.');
        var padding = Array(5 - ((b64text.length % 4) || 4)).join(alphabet[alphabet.length - 1]);
        b64text += padding; // pad with last letter of alphabet, so math works out
        var out_array = [];
        for (var i=0, n=b64text.length; i < n; i+=4) {
          newchars = (
            (decode_map[b64text[i]]   << 18) +
            (decode_map[b64text[i+1]] << 12) +
            (decode_map[b64text[i+2]] << 6)  +
            (decode_map[b64text[i+3]]));
          out_array.push(
            (newchars >> 020) & 0xFF,
            (newchars >> 010) & 0xFF,
            (newchars)        & 0xFF);
        };
        shorten(out_array, padding.length); // strip 'decoded' padding
        return String.fromCharCode.apply(String, out_array);
      };
      return codec;
    };
    var base64 = this.base64 = base64Codec(
      'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef' +
      'ghijklmnopqrstuvwxyz0123456789+/', '=');
    var base64_urlsafe = this.base64_urlsafe = base64Codec(
      'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef' +
      'ghijklmnopqrstuvwxyz0123456789-_', '='); // lenient input/output
      

function encryptBase64() {
    document.getElementById("resulttext").innerHTML = "Káº¿t quáº£ MÃ£ hÃ³a:";
    document.helloximoBase64.T2Base64.value = base64.encode(document.helloximoBase64.T1Base64.value);
    return !1
}
function decryptBase64() {
    document.getElementById("resulttext").innerHTML = "Káº¿t quáº£ Giáº£i mÃ£:";
    document.helloximoBase64.T2Base64.value = base64.decode(document.helloximoBase64.T1Base64.value);
    return !1
}





    var base64Codec = function (alphabet, padCharacter) {
      // Returns an object with 'encode' and 'decode' functions for the specified
      // 64-character 'alphabet'
      if (alphabet.length != 64) { throw new Error('Alphabet must be 64 characters.') };
      var codec = {};
      var decode_map = {};
      for (var i=0, n=alphabet.length; i < n; i++) {
        decode_map[alphabet[i]] = i;
      };
      // used to sniff out characters outside the alphabet
      var alphabet_inverse_regexp = new RegExp('[^' + alphabet.replace(/[\.\^\$\*\+\?\{\[\]\\\|\(\)]/g, '\\$&') + ']');
      codec.Base64CodecError = function (message) { this.message = message; };
      codec.Base64CodecError.prototype.toString = function () {
        return 'Base64CodecError' + (this.message ? ': ' + this.message : '');
      };
      var assertOrBadInput = function (expression, message) {
        if (!expression) { throw new codec.Base64CodecError(message) };
      };
      codec.encode = function (bytes, padOutput) {
        if (padOutput == null) { padOutput = true; }; // default to strict output
        assertOrBadInput(!(/[^\x00-\xFF]/.test(bytes)), 'Input contains out-of-range characters.'); // disallow two-byte chars
        var padding = '\x00\x00\x00'.slice((bytes.length % 3) || 3);
        bytes += padding; // pad with null bytes
        var out_array = [];
        for (var i=0, n=bytes.length; i < n; i+=3) {
          var newchars = (
            ((bytes.charCodeAt(i)  ) << 020) +
            ((bytes.charCodeAt(i+1)) << 010) +
            ((bytes.charCodeAt(i+2))));
          out_array.push(
            alphabet[(newchars >> 18) & 077],
            alphabet[(newchars >> 12) & 077],
            alphabet[(newchars >> 6)  & 077],
            alphabet[(newchars)       & 077]);      
        };
        output_padding = (padOutput && padCharacter !== undefined) ?
          Array(5).join(padCharacter).slice(-padding.length) :
          '';
        shorten(out_array, padding.length);
        return out_array.join('') + output_padding;
      };
      codec.link2 = function (b64text, requirePadding, disallowWhitespace) {
        // by default don't require padding, and allow whitespace.
        if (!disallowWhitespace) { b64text = b64text.replace(/\s/g, ''); }; // kill whitespace
        if (padCharacter != null) {
          assertOrBadInput(!requirePadding || !(b64text.length % 4), 'Input length not divisible by 4.');
          b64text = rstrip(b64text, padCharacter)
        };
        assertOrBadInput(!alphabet_inverse_regexp.test(b64text), 'Input contains out-of-range characters.');
        var padding = Array(5 - ((b64text.length % 4) || 4)).join(alphabet[alphabet.length - 1]);
        b64text += padding; // pad with last letter of alphabet, so math works out
        var out_array = [];
        for (var i=0, n=b64text.length; i < n; i+=4) {
          newchars = (
            (decode_map[b64text[i]]   << 18) +
            (decode_map[b64text[i+1]] << 12) +
            (decode_map[b64text[i+2]] << 6)  +
            (decode_map[b64text[i+3]]));
          out_array.push(
            (newchars >> 020) & 0xFF,
            (newchars >> 010) & 0xFF,
            (newchars)        & 0xFF);
        };
        shorten(out_array, padding.length); // strip 'decoded' padding
        return String.fromCharCode.apply(String, out_array);
      };
      return codec;
    };
    var link2 = this.link2 = base64Codec(
      'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef' +
      'ghijklmnopqrstuvwxyz0123456789+/', '=');
    var base64_urlsafe = this.base64_urlsafe = base64Codec(
      'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef' +
      'ghijklmnopqrstuvwxyz0123456789-_', '='); // lenient input/output


/* Loáº¡i 2 táº¡m thá»i khÃ´ng dÃ¹ng
var base64 = {
    _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
    encode: function (c) {
        for (var a = "", d, b, f, g, h, e, i = 0, c = base64._utf8_encode(c); i < c.length;) d = c.charCodeAt(i++),
        b = c.charCodeAt(i++),
        f = c.charCodeAt(i++),
        g = d >> 2,
        d = (d & 3) << 4 | b >> 4,
        h = (b & 15) << 2 | f >> 6,
        e = f & 63,
        isNaN(b) ? h = e = 64 : isNaN(f) && (e = 64),
        a = a + this._keyStr.charAt(g) + this._keyStr.charAt(d) + this._keyStr.charAt(h) + this._keyStr.charAt(e);
        return a
    },

    decode: function (c) {
        for (var a = "", d, b, f, g, h, e = 0, c = c.replace(/[^A-Za-z0-9\+\/\=]/g, ""); e < c.length;) d = this._keyStr.indexOf(c.charAt(e++)),
        b = this._keyStr.indexOf(c.charAt(e++)),
        g = this._keyStr.indexOf(c.charAt(e++)),
        h = this._keyStr.indexOf(c.charAt(e++)),
        d = d << 2 | b >> 4,
        b = (b & 15) << 4 | g >> 2,
        f = (g & 3) << 6 | h,
        a += String.fromCharCode(d),
        64 != g && (a += String.fromCharCode(b)),
        64 != h && (a += String.fromCharCode(f));
        return a = base64._utf8_decode(a)
    },

    _utf8_encode: function (c) {
        for (var c = c.replace(/\r\n/g, "\n"), a = "", d = 0; d < c.length; d++) {
            var b = c.charCodeAt(d);
            128 > b ? a += String.fromCharCode(b) : (127 < b && 2048 > b ? a += String.fromCharCode(b >> 6 | 192) : (a += String.fromCharCode(b >> 12 | 224), a += String.fromCharCode(b >> 6 & 63 | 128)), a += String.fromCharCode(b & 63 | 128))
        }
        return a
    },

    _utf8_decode: function (c) {
        for (var a = "", d = 0, b = c1 = c2 = 0; d < c.length;) b = c.charCodeAt(d),
        128 > b ? (a += String.fromCharCode(b), d++) : 191 < b && 224 > b ? (c2 = c.charCodeAt(d + 1), a += String.fromCharCode((b & 31) << 6 | c2 & 63), d += 2) : (c2 = c.charCodeAt(d + 1), c3 = c.charCodeAt(d + 2), a += String.fromCharCode((b & 15) << 12 | (c2 & 63) << 6 | c3 & 63), d += 3);
        return a
    }
}

*/


/* Loáº¡i 3 táº¡m thá»i khÃ´ng dÃ¹ng
 var keyStr = "ABCDEFGHIJKLMNOP" +
	               "QRSTUVWXYZabcdef" +
	               "ghijklmnopqrstuv" +
	               "wxyz0123456789+/" +
	               "=";

	  function en64(input) {
	     input = escape(input);
	     var output = "";
	     var chr1, chr2, chr3 = "";
	     var enc1, enc2, enc3, enc4 = "";
	     var i = 0;
	 
	     do {
	        chr1 = input.charCodeAt(i++);
	        chr2 = input.charCodeAt(i++);
	        chr3 = input.charCodeAt(i++);
	 
	        enc1 = chr1 >> 2;
	        enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
	        enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
	        enc4 = chr3 & 63;
	 
	        if (isNaN(chr2)) {
	           enc3 = enc4 = 64;
	        } else if (isNaN(chr3)) {
	           enc4 = 64;
	        }
	 
	        output = output +
	           keyStr.charAt(enc1) +
	           keyStr.charAt(enc2) +
	           keyStr.charAt(enc3) +
	           keyStr.charAt(enc4);
	        chr1 = chr2 = chr3 = "";
	        enc1 = enc2 = enc3 = enc4 = "";
	     } while (i < input.length);
	 
	     return output;
	  }



	  function de64(input) { // Tá»©c lÃ  hÃ m giáº£i mÃ£ de64
	     var output = "";
	     var chr1, chr2, chr3 = "";
	     var enc1, enc2, enc3, enc4 = "";
	     var i = 0;	 
	     // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
	     var base64test = /[^A-Za-z0-9\+\/\=]/g;
	     if (base64test.exec(input)) {
	        alert("There were invalid base64 characters in the input text.\n" +
	              "Valid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='\n" +
	              "Expect errors in decoding.");
	     }
	     input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
	 
	     do {
	        enc1 = keyStr.indexOf(input.charAt(i++));
	        enc2 = keyStr.indexOf(input.charAt(i++));
	        enc3 = keyStr.indexOf(input.charAt(i++));
	        enc4 = keyStr.indexOf(input.charAt(i++));
	 
	        chr1 = (enc1 << 2) | (enc2 >> 4);
	        chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
	        chr3 = ((enc3 & 3) << 6) | enc4;
	 
	        output = output + String.fromCharCode(chr1);
	 
	        if (enc3 != 64) {
	           output = output + String.fromCharCode(chr2);
	        }
	        if (enc4 != 64) {
	           output = output + String.fromCharCode(chr3);
	        }
	 
	        chr1 = chr2 = chr3 = "";
	        enc1 = enc2 = enc3 = enc4 = "";
	 
	     } while (i < input.length);
	 
	     return unescape(output);
	  }

 */

